package com.itheima.map;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class StreamDemo {
    public static void main(String[] args) {
        ArrayList<String> list=new ArrayList<String>();
        list.add("zhangsan,55");
        list.add("lisi,23");
        list.add("laoliu,909");
        list.add("tianqi,456");
        list.add("tianqi,456");
      //  list.add("tianqi,45");
        list.add("tianqi,456");

        //list.stream().filter(s->Integer.parseInt(s.split(",")[1])%2==0).forEach(s-> System.out.println(s));
 /*       List<String> list1=list.stream().filter(s->Integer.parseInt(s.split(",")[1])%2==0)
                .collect(Collectors.toList());
        System.out.println(list1);

        Set<String> collect = list.stream().collect(Collectors.toSet());
        System.out.println(collect);
*/
//distinct() 去除重复
        Map<String,String> map= list.stream().distinct().collect(Collectors.toMap(
                (String s)->{
//                    String[] a=s.split(",");
//                    return a[0];
                    return s.split(",")[0];

                },
                (String s)->{
//                    String[] a= s.split(",");
//                    return a[1];
                    return s.split(",")[1];
                }
                )
        );
        System.out.println(map);
    }
}
